import cv2
import numpy as np

# 读取图像
image = cv2.imread('example.jpg')

# 定义平移矩阵
# 假设向右平移50像素，向下平移30像素
M = np.float32([[1, 0, 50], [0, 1, 30]])

# 进行平移
translated_image = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))

# 保存平移后的图像
cv2.imwrite('translated_image.jpg', translated_image)